package org.fusionide.builder.parsers.cfml.tags;

import org.fusionide.builder.parsers.IParserHandler;
import org.fusionide.builder.parsers.ParserException;
import org.fusionide.builder.parsers.cfml.CFMLTag;

public class QueryParam extends CFMLTag {
	private String cfsqltype;

	private String list;

	private String maxlength;

	private String nullValue;

	private String scale;

	private String separator;

	private String value;

	public QueryParam(String attributes, int startOffset) {
		super(attributes, startOffset);
		if (attributes == null)
			return;
		this.cfsqltype = getAttribute("cfsqltype");
		this.list = getAttribute("list");
		this.maxlength = getAttribute("maxlength");
		this.nullValue = getAttribute("null");
		this.scale = getAttribute("scale");
		this.separator = getAttribute("separator");
		this.value = getAttribute("value");
	}

	@Override
	public boolean requiresClosingTag() {
		return false;
	}

	@Override
	public boolean acceptsChildren(CFMLTag tag) {
		return false;
	}

	@Override
	public boolean validate(IParserHandler parserHandler) {
		if (super.validate(parserHandler)) {
//			if (!validateSqlType()) {
//				if (parserHandler != null)
//					parserHandler.addMarker(new ParserException("<cfqueryparam> Invalid CfSqlType", ParserException.SEVERITY_ERROR, startLine));
//				return false;
//			}
			return true;
		}
		return false;
	}

	private boolean validateSqlType() {
		if (cfsqltype == null)
			return false;
		if (cfsqltype.equalsIgnoreCase("cf_sql_bigint"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_bit"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_blob"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_char"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_clob"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_date"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_decimal"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_double"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_float"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_idstamp"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_integer"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_longvarchar"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_money"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_money4"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_numeric"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_real"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_refcursor"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_smallint"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_time"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_timestamp"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_tinyint"))
			return true;
		if (cfsqltype.equalsIgnoreCase("cf_sql_varchar"))
			return true;
		return false;
	}
}
